import urllib.request
import gevent
from gevent import monkey


def test_http():
    request = urllib.request.urlopen("http://www.zxit8.com/")
    content = request.read()
    print(content)


def download_image(file_name, image_url):
    monkey.patch_all()
    request = urllib.request.urlopen(image_url)
    image_content = request.read()
    # 保存图片
    with open(file_name, "wb") as image_file:
        image_file.write(image_content)


def main():
    gevent.joinall([
        gevent.spawn(download_image, "./1.jpg",
                     "https://preview.qiantucdn.com/58pic/35/63/53/86x58PICNYjc653WHRz69_PIC2018.jpg!qt324new_nowater_webp"),
        gevent.spawn(download_image, "./2.jpg",
                     "http://www.zxit8.com/data/attachment/forum/201904/14/150213sri2difiyzppi62o.png"),
        gevent.spawn(download_image, "./3.mp4",
                     "https://v.youku.com/v_show/id_XNDUyMDA1NjU0MA==.html?spm=a2hcb.12675304.m_7182_c_14738.d_5&s=edde3effe5f94af495e5&scm=20140719.rcmd.7182.show_edde3effe5f94af495e5")
    ])


if __name__ == '__main__':
    main()
